package com.hjq.controller;

import com.hjq.common.PageResult;
import com.hjq.common.Result;
import com.hjq.entity.po.Carousel;
import com.hjq.entity.vo.PageParam;
import com.hjq.service.CarouselService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图管理
 */
@Slf4j
@RestController
@RequestMapping("/carousel")
public class CarouselController {
    @Autowired
    private CarouselService carouselService;
    /**
     * 分页查询轮播图
     * @param pageParam 分页参数
     * @return PageResult
     */
    @GetMapping
    public Result<PageResult<Carousel>> list(PageParam pageParam) {
        log.info("分页查询轮播图,{}",pageParam);
        PageResult<Carousel> result = carouselService.findByPage(pageParam);
        return  Result.success(result);
    }
    /**
     * 添加轮播图
     * @param carousel 轮播图
     */
    @PostMapping
    public Result<Object> add(@RequestBody Carousel carousel){
        log.info("添加轮播图,{}",carousel);
        carouselService.add(carousel);
        return Result.success("添加成功");
    }
    /**
     * 删除轮播图
     * @param id 轮播图ID
     */
    @DeleteMapping("/{id}")
    public Result<Object> delete(@PathVariable Integer id) {
        carouselService.delete(id);
        return Result.success("删除成功");
    }
    /**
     * 修改轮播图
     * @param carousel 轮播图
     */
    @PutMapping
    public Result<Object> update(@RequestBody Carousel carousel) {
        log.info("修改轮播图,{}",carousel);
        carouselService.update(carousel);
        return Result.success("修改成功");
    }

}
